import { forwardRef, useRef } from 'react';
import { GModalForm, GSelect } from 'geminis-react';
import { message } from 'antd';

export const ContainerSelect = forwardRef((props: any, ref: any) => {
  const selectRef = useRef<any>();

  return (
    <>
      <GSelect
        style={{ width: '70%', marginRight: '5px' }}
        fieldNames={{
          label: 'no',
          value: 'id',
        }}
        ref={selectRef}
        url={'/api/warehouse/inventory/container'}
        method="POST"
        filter={props?.filter}
        showSearch
        onChange={props?.onChange}
        value={props?.value}
      />
      <GModalForm
        button={{
          text: '新增',
        }}
        form={{
          schema: {
            data: {
              url: '/api/warehouse/inventory/container',
            },
          },
          schemaPath: '/warehouse-pc/schemas/inventory/container/edit.json',
          onSubmitted: () => {
            message.success('添加成功');
            selectRef.current.loadData();
          },
        }}
      />
    </>
  );
});
